package com.xm.xmapp;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Intent;
import android.location.Location;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.DrawerLayout.DrawerListener;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.amap.api.maps.AMap;
import com.amap.api.maps.AMapUtils;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.LocationSource;
import com.amap.api.maps.MapView;
import com.amap.api.maps.UiSettings;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.LatLngBounds;
import com.amap.api.maps.model.LatLngBounds.Builder;
import com.amap.api.maps.model.MyLocationStyle;
import com.amap.api.navi.model.NaviLatLng;
import com.android.volley.VolleyError;
import com.nineoldandroids.view.ViewHelper;
import com.xm.xmapp.adapter.FragmentStatePagerAdapter;
import com.xm.xmapp.app.CodeConstant;
import com.xm.xmapp.app.MyAppcation;
import com.xm.xmapp.app.Type;
import com.xm.xmapp.base.BaseActivity;
import com.xm.xmapp.customview.LongRentTipDialog;
import com.xm.xmapp.customview.MyViewPager;
import com.xm.xmapp.customview.ScrollDownLayout;
import com.xm.xmapp.customview.ScrollDownLayout.OnScrollChangedListener;
import com.xm.xmapp.customview.ScrollDownLayout.Status;
import com.xm.xmapp.customview.TipDialog;
import com.xm.xmapp.customview.ZoomOutPageTransformer;
import com.xm.xmapp.dialog.GuideDialog;
import com.xm.xmapp.dialog.NoticeTipDialog;
import com.xm.xmapp.dialog.PersonProblemDialog;
import com.xm.xmapp.dialog.PilePasswordDialog;
import com.xm.xmapp.dialog.PilePasswordDialog.DissMissable;
import com.xm.xmapp.exception.MyException;
import com.xm.xmapp.fragment.BigCustomerCarInfoFragment;
import com.xm.xmapp.fragment.BigCustomerRentcarFragment;
import com.xm.xmapp.fragment.BigCustomerSubscribeFragment;
import com.xm.xmapp.fragment.LongTimeCarInfoFragment;
import com.xm.xmapp.fragment.LongTimeRentCarFragment;
import com.xm.xmapp.fragment.LongTimeSubscribeFragment;
import com.xm.xmapp.fragment.MainBottomFragment;
import com.xm.xmapp.fragment.MainLeftFragment;
import com.xm.xmapp.fragment.MainTopFragment;
import com.xm.xmapp.fragment.NoCarInfoFragment;
import com.xm.xmapp.fragment.PileInfoFragment;
import com.xm.xmapp.fragment.PileUseFragment;
import com.xm.xmapp.fragment.ShortTimeCarInfoFragment;
import com.xm.xmapp.fragment.ShortTimeRentcarFragment;
import com.xm.xmapp.fragment.ShortTimeSubscribeFragment;
import com.xm.xmapp.map.ClusterClickListener;
import com.xm.xmapp.map.ClusterItem;
import com.xm.xmapp.map.MapOverlay;
import com.xm.xmapp.map.SensorEventHelper;
import com.xm.xmapp.myinterface.DisssmissInterFace;
import com.xm.xmapp.myinterface.GetDataInterFace;
import com.xm.xmapp.myinterface.MainActivityInterFace;
import com.xm.xmapp.myinterface.MainInterFaceAble;
import com.xm.xmapp.myinterface.MyDialogButton;
import com.xm.xmapp.myinterface.ScrollInterFaceAble;
import com.xm.xmapp.request.bean.Big_customer_get_user_car_orderRequest;
import com.xm.xmapp.request.bean.Check_orderRequest;
import com.xm.xmapp.request.bean.GetNetworkImgsRequest;
import com.xm.xmapp.request.bean.Get_all_message_idRequest;
import com.xm.xmapp.request.bean.Get_all_networkRequest;
import com.xm.xmapp.request.bean.Get_all_network_coordsRequest;
import com.xm.xmapp.request.bean.Get_big_customer_invite_infoRequest;
import com.xm.xmapp.request.bean.Get_car_list_Request;
import com.xm.xmapp.request.bean.Get_longrent_order_infoRequest;
import com.xm.xmapp.request.bean.Get_network_car_genre_listRequest;
import com.xm.xmapp.request.bean.Get_network_car_list_infoRequest;
import com.xm.xmapp.request.bean.Get_network_infoRequest;
import com.xm.xmapp.request.bean.Get_now_car_orderRequest;
import com.xm.xmapp.request.bean.NoticeRequest;
import com.xm.xmapp.request.bean.Qr_carRequest;
import com.xm.xmapp.request.bean.RequestGetDriverLicenseReviewInfo;
import com.xm.xmapp.request.bean.RequestPileNetworkInfo;
import com.xm.xmapp.request.bean.Seek_carResponse;
import com.xm.xmapp.request.bean.Start_chargeRequest;
import com.xm.xmapp.response.bean.BaseBeanResponse;
import com.xm.xmapp.response.bean.BigCustomerOrderBean;
import com.xm.xmapp.response.bean.CarInfoBean;
import com.xm.xmapp.response.bean.CheckOrderBean;
import com.xm.xmapp.response.bean.CustomHeightBean;
import com.xm.xmapp.response.bean.DaKeHuYuYueBean;
import com.xm.xmapp.response.bean.Get_network_car_genre_listResponse;
import com.xm.xmapp.response.bean.InterFaceBigCustomerOrderBeanAble;
import com.xm.xmapp.response.bean.JpushNotifactionResponse;
import com.xm.xmapp.response.bean.JpushReceiverResponse;
import com.xm.xmapp.response.bean.LongRentOrderBean;
import com.xm.xmapp.response.bean.LongRentSubscribeBean;
import com.xm.xmapp.response.bean.NoticeResponse;
import com.xm.xmapp.response.bean.ResponseAllMessageId;
import com.xm.xmapp.response.bean.ResponseAllNetwork;
import com.xm.xmapp.response.bean.ResponseAllNetwork.PileNetWork;
import com.xm.xmapp.response.bean.ResponseAllNetworkCoords;
import com.xm.xmapp.response.bean.ResponseAllNetworkCoords.Point;
import com.xm.xmapp.response.bean.ResponseAppUserOrder;
import com.xm.xmapp.response.bean.ResponseBigCustomerInviteInfo;
import com.xm.xmapp.response.bean.ResponseBigCustomerOrder;
import com.xm.xmapp.response.bean.ResponseCarList;
import com.xm.xmapp.response.bean.ResponseGetDriverLicenseReviewInfo;
import com.xm.xmapp.response.bean.ResponseLongRentOrder;
import com.xm.xmapp.response.bean.ResponsePileNetworkInfo;
import com.xm.xmapp.response.bean.ResponsePlieNetworkInfo;
import com.xm.xmapp.response.bean.ResponseSearchHistory;
import com.xm.xmapp.response.bean.ResponseShortTimeOrder;
import com.xm.xmapp.response.bean.ResponseStartCharge;
import com.xm.xmapp.response.bean.ResponseUserBean;
import com.xm.xmapp.response.bean.SubscribeOrderInfo;
import com.xm.xmapp.test.DrawButton;
import com.xm.xmapp.tools.Helper_SharedPreferences;
import com.xm.xmapp.tools.Log;
import com.xm.xmapp.tools.MyCache;
import com.xm.xmapp.tools.StringTools;
import com.xm.xmapp.tools.SwapData;
import com.xm.xmapp.tools.TimeUtil;
import com.xm.xmapp.tools.TimeUtil.TimeListener;
import com.xm.xmapp.tools.Tools;



@SuppressLint("InflateParams")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public class MainActivity extends BaseActivity implements ClusterClickListener,
		OnClickListener, OnScrollChangedListener, AMap.OnMyLocationChangeListener {
	/**
	 * 长租，分时，大客户预约订单以及订单显示
	 */
	private LongTimeSubscribeFragment mLongTimeSubscribeFrament;
	private LongTimeRentCarFragment mLongTimeRentCarFrament;
	private ShortTimeSubscribeFragment mShortTimeSubscribeFrament;
	private BigCustomerSubscribeFragment mBigCustomerSubscribeFrament;
	private Fragment fragment;// 目前正在展示的订单fragment

	private AMap mAMap;
	private MapView mMapView;
	private MyViewPager mViewPage;
	private FragmentStatePagerAdapter adapter;
	private ScrollDownLayout mScrollDownLayout, mScrollDownLayoutLongRent;
	private MainActivityInterFace mainActivityInterFace;
	private MainLeftFragment mMainLeftFragment;
	private MainTopFragment mMainTopFragment;
	private MainBottomFragment mMainBottomFragment;
	private GuideDialog guideDialog;// 引导页Dialog
	private MapOverlay mMapOverlay;
	private DrawButton mDrawButton;
	private DrawerLayout mDrawerLayout;// 抽屉布局
	private ImageView iv_using_car;

	private ResponseShortTimeOrder mShortTimeOrderBean;// 分时是否有预定车辆信息
	private ResponseLongRentOrder mLongRentOrderBean;// 长租订单信息
	private ResponseBigCustomerOrder mBigCustomerOrderBean;// 大客户订单
	private ResponseStartCharge start_chargeBean;
	private DisssmissInterFace mDisssmissInterFace;
	private boolean isExit = false;// 两次退出app
	private boolean isFirst = true;// 初次，或者重新进入首页，显示定位点与最近的一个网点
	private TimeUtil mTask;// 定时任务，每个隔一段时间获取网点信息
	private boolean isFirstInter = true;// 是否是第一次进入页面，是，并且还有长租预约订单，就显示提示dialog；

	private ArrayList<ClusterItem> mPileList = new ArrayList<ClusterItem>();// 充电桩网点显示
	private ArrayList<ClusterItem> mShortList = new ArrayList<ClusterItem>();// 分时租赁网点
	private ArrayList<ClusterItem> mLongList = new ArrayList<ClusterItem>();// 长租网点
	private ArrayList<Fragment> fragmentList = new ArrayList<Fragment>();// 分时网店汽车列表，大客户汽车列表,其它单页fragment
	private ArrayList<ClusterItem> mShortCarList = new ArrayList<ClusterItem>();// //分时小汽车数据列表
	private ArrayList<ClusterItem> mBigCustomerCarList = new ArrayList<ClusterItem>();// 大客户小汽车数据列表

	private boolean isBigCustomer = false;// 是否是大客户
	private boolean isInit = true;// 首页是否需要初始化，仅对首页做特殊处理getLastData方法里使用，当系统由于内存不足，清掉activity数据时
	private int isFrom;// 默认是从登录页面跳转 0表示从登录页面跳转过来1表示从注册页面跳转过来(需要提示是否去认证)
	private ClusterItem item;// 保存每次点击的单个网点信息

	/**
	 * FLAG_SHORT_TIME是分时 FLAG__LONG_RENT是长租 FLAG_PILE.电桩 FLAG_BIGCUSTOME.大客戶
	 */
	private int flag_status;
	public static final int FLAG_SHORT_TIME = 0; // 分时
	public static final int FLAG__LONG_RENT = 1;// 长租
	public static final int FLAG_PILE = 2;// 电桩
	public static final int FLAG_BIGCUSTOME = 3;// 大客戶

	/**
	 * -1表示开始充电1登陸頁面調用,2.消息页面调用,3.极光推送(预约，下单),4突然有网咯连接,6长租预约订单提交或者取消后调用（
	 * LongRentOrderYuyueActivity）以及支付成功后调用（WXPayEntryActivity
	 * 和StartToPayLongRentOrderActivity）7车辆被租用，重新拉取单个网点信息 CarInfoFrament调用9
	 * 执行ScrollViewInterFace接口中的方法10退出大客户页面调用11点击寻车按钮12分时还车页面获取所有网店数据
	 */
	@Override
	public Object dataChang(int flag, Object data) {

		switch (flag) {
		case Type.A_Main.START_CHANG: {
			ResponseStartCharge start_chargeBean = (ResponseStartCharge) data;
			setPileOrder(start_chargeBean);
			break;
		}
		case Type.A_Main.LOGIN_CODE: {
			if (MyAppcation.getMyAppcation().getUserBean() != null) {
				getMessageId();
				getOrderInfo();
			}
			break;
		}
		case Type.A_Main.MSG_CODE: {
			ResponseAllMessageId messageServerBean = (ResponseAllMessageId) Helper_SharedPreferences
					.get_obj_sp(CodeConstant.messageServer);
			ResponseAllMessageId messageClientBean = (ResponseAllMessageId) Helper_SharedPreferences
					.get_obj_sp(CodeConstant.messageClient);
			setMessage(messageServerBean, messageClientBean);
			break;
		}
		case Type.A_Main.JPUSH_CODE: {
			JpushReceiverResponse bean = (JpushReceiverResponse) data;
			switch (bean.type) {
			case JpushReceiverResponse.SHORT_TIME_NO_FROM_SUB:
			case JpushReceiverResponse.SHORT_TIME_ORDER:
			case JpushReceiverResponse.SHORT_TIME_SUBSCRIBE:
			case JpushReceiverResponse.SHORT_TIME_SEND:
				if (MyAppcation.getMyAppcation().getUserBean() != null) {
					getOrderInfo();
				}
				break;
			case JpushReceiverResponse.SHORT_TIME_NO_FROM_ORDER:
				mShortTimeOrderBean.orderType = ResponseShortTimeOrder.NO_ORDER_CODE;
				mScrollDownLayout.setToExitOffset();
				MyAppcation.getMyAppcation().notifyDataSetChanged(ShortTimeRentcarFragment.class, 0, null);
				break;
			case JpushReceiverResponse.BIGCUSTOMER_IN:
				if (mMainLeftFragment != null) {
					mMainLeftFragment.get_big_customer_invite_info(false);
				}
				break;
			case JpushReceiverResponse.BIGCUSTOMER_OUT:
				ResponseUserBean userBean = MyAppcation.getMyAppcation().getUserBean();
				userBean.is_big_customer_user = 0;
				MyAppcation.getMyAppcation().saveUserBean(userBean);
				if (mMainLeftFragment != null) {
					mMainLeftFragment.setData();
				}
				if (isBigCustomer) {

//					text.get(FLAG_BIGCUSTOME).setVisibility(View.GONE);
//					text.get(FLAG_SHORT_TIME).setVisibility(View.VISIBLE);
//					text.get(FLAG__LONG_RENT).setVisibility(View.VISIBLE);
					setFlag(FLAG_SHORT_TIME);
					isBigCustomer = !isBigCustomer;
				}
				break;

			case JpushReceiverResponse.BIGCUSTOMER_SUBSCRIBE:
			case JpushReceiverResponse.BIGCUSTOMER_ORDER:
			case JpushReceiverResponse.BIGCUSTOMER_NO_FROM_ORDER:
			case JpushReceiverResponse.BIGCUSTOMER_NO_FROM_SUB:
				if (flag_status == FLAG_BIGCUSTOME) {
					getBigCustomerOrder();
				}
				break;
			case JpushReceiverResponse.PILE:
				if (MyAppcation.getMyAppcation().getUserBean() != null) {
					getPileOrder();
				}
				break;
			default:
				break;
			}
			break;
		}
		case Type.A_Main.NETWORK_CHANGE_CODE: {
			if (MyAppcation.getMyAppcation().getUserBean() != null) {
				getMessageId();
				getOrderInfo();
			}
			break;
		}
		case Type.A_Main.LONGRENT_ORDER_CHANGE: {
			mScrollDownLayout.setToExitOffset();
			getLongRentOrderInfo();
			break;
		}
		case Type.A_Main.CAR_HAVE_RENT_CODE: {
			if (this.item != null) {
				getNetworkCarsInfo();
			}
			break;
		}
		case Type.A_Main.CHANGE_UI_CODE: {
			if (mainActivityInterFace != null) {
				CustomHeightBean heightBean = (CustomHeightBean) data;
				if (heightBean != null) {
					mainActivityInterFace.doInUIdata(heightBean.flag, data);
				}
			}
			break;
		}
		case Type.A_Main.QUIT_BIGCUSTOM_CODE: {
			if (isBigCustomer) {
				isBigCustomer = !isBigCustomer;
				mMainTopFragment.setBigCustomer(isBigCustomer);
			}
			break;
		}
		case Type.A_Main.SEARCH_CAR_CODE: {
			Seek_carResponse seek_carResponse = (Seek_carResponse) data;
			mMapOverlay.setMyCar(seek_carResponse);
			break;
		}
		case Type.A_Main.SHORT_RENT_CODE: {
			return mShortList;
		}
		case Type.A_Main.SHORT_RENT_GET_CAR: {
			getNetworkCoords();
			break;
		}
		default:
			break;
		}
		return super.dataChang(flag, data);
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		MyAppcation.getMyAppcation().reMoveAllBaseInterFace();
		isUsePad = false;
		super.onCreate(savedInstanceState);
		if (isInit) {
			/**
			 * 进入主页，清理一次数据
			 */
			Helper_SharedPreferences.clear_sharePref(CodeConstant.Get_all_network_coords_time);
			Helper_SharedPreferences.clear_sharePref(CodeConstant.Get_all_network_time);
			setContentView(R.layout.activity_main);
			mMapView.onCreate(savedInstanceState);
			initSlidingMenu(savedInstanceState);
			startLocation();
		}
	}

	/**
	 * 初始化侧边栏
	 */
	private void initSlidingMenu(Bundle savedInstanceState) {
//		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//			View content = mDrawerLayout.getChildAt(0);
//			content.setPadding(0, statusBarHeight2, 0, 0);
//		}
		if (MyAppcation.getMyAppcation().getUserBean() == null) {
			mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
		} else {
			mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
		}
		mDrawerLayout.addDrawerListener(new DrawerListener() {
			@Override
			public void onDrawerStateChanged(int newState) {
			}

			@Override
			public void onDrawerSlide(View drawerView, float slideOffset) {
				View mContent = mDrawerLayout.getChildAt(0);
				View mMenu = drawerView;
				float scale = 1 - slideOffset;
				if (drawerView.getTag().equals("LEFT")) {
					ViewHelper.setTranslationX(mContent, mMenu.getMeasuredWidth() * (1 - scale));
					mContent.invalidate();
				}
			}

			@Override
			public void onDrawerOpened(View drawerView) {
			}

			@Override
			public void onDrawerClosed(View drawerView) {
			}
		});

	}

	/**
	 * 设置充电信息
	 *
	 * @param start_chargeBean
	 */
	private void setPileOrder(ResponseStartCharge start_chargeBean) {

		if (start_chargeBean == null) {
			this.start_chargeBean = start_chargeBean;
			if (fragmentList.size() > 0 && fragmentList.get(0) instanceof PileUseFragment) {
				mScrollDownLayout.setToExitOffset();
			}
			return;
		}
		if (fragmentList != null) {
			boolean isSameOrder = false;
			if (start_chargeBean != null && this.start_chargeBean != null
					&& start_chargeBean.orderNo.equals(this.start_chargeBean.orderNo)) {
				isSameOrder = true;
			} else {
				this.start_chargeBean = start_chargeBean;
			}
			if (fragmentList.size() > 0 && fragmentList.get(0) instanceof PileUseFragment && isSameOrder) {
				mScrollDownLayout.setToMinOffset();
			} else {
				fragmentList.clear();
				PileUseFragment usePileFragment = new PileUseFragment();
				usePileFragment.setStart_chargeBean(start_chargeBean);
				fragmentList.add(usePileFragment);
				setViewPageAdapter();
			}
		} else {
			fragmentList = new ArrayList<Fragment>();
			PileUseFragment usePileFragment = new PileUseFragment();
			usePileFragment.setStart_chargeBean(start_chargeBean);
			fragmentList.add(usePileFragment);
			setViewPageAdapter();
			this.start_chargeBean = start_chargeBean;
		}

	}

	public void initView() {

		mMapView = (MapView) findViewById(R.id.map);

//		TextView text_title = (TextView) findViewById(R.id.fenshi);
//		text.put(FLAG_SHORT_TIME, text_title);
//		text_title = (TextView) findViewById(R.id.rizu);
//		text.put(FLAG__LONG_RENT, text_title);
//		text_title = (TextView) findViewById(R.id.yuezu);
//		text.put(FLAG_PILE, text_title);
//		text_title = (TextView) findViewById(R.id.dakehu);
//		text.put(FLAG_BIGCUSTOME, text_title);

		mViewPage = (MyViewPager) findViewById(R.id.vp);
		mDrawButton = (DrawButton) findViewById(R.id.button);
		iv_using_car = (ImageView) findViewById(R.id.iv_using_car);
		mScrollDownLayout = (ScrollDownLayout) findViewById(R.id.scroll_down_layout);
		mScrollDownLayoutLongRent = (ScrollDownLayout) findViewById(R.id.sdl_longrent);
		mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
		iv_using_car = (ImageView) findViewById(R.id.iv_using_car);

		initmScrollDownLayout();
		if (mAMap == null) {
			mAMap = mMapView.getMap();
		}

	}

	private void initmScrollDownLayout() {

		mainActivityInterFace = new MainActivityInterFace() {

			@Override
			public void doInUIdata(int flag, Object data) {

				CustomHeightBean bean;
				switch (flag) {
				case STOP_CHANGING: {
					mScrollDownLayout.setToExitOffset();
					break;
				}
				case INTT_STATUS: {
					bean = (CustomHeightBean) data;
					if (bean != null) {
						mScrollDownLayout.setMinOffset(0);
						mScrollDownLayout.setMaxOffset(bean.MaxOffset);
						mScrollDownLayout.setExitOffset(bean.ExitOffset);

					}
					mScrollDownLayout.setToMinOffset();
					break;
				}
				case INTT_STATUS_NO_ONCLICK: {
					bean = (CustomHeightBean) data;
					// 是否跟上一次设置的参数一样
//					boolean haveNoSetting = (mScrollDownLayout.getMaxOffset() != bean.MaxOffset && mScrollDownLayout
//							.getExitOffset() != bean.ExitOffset)
//							|| mScrollDownLayout.getCurrentInnerStatus() == ScrollDownLayout.InnerStatus.EXIT;
					if (bean != null ) {
						mScrollDownLayout.setMinOffset(0);
						mScrollDownLayout.setMaxOffset(bean.MaxOffset);
						mScrollDownLayout.setExitOffset(bean.ExitOffset);
						mScrollDownLayout.setToMinOffset();
//						mScrollDownLayout.startAnimat();
					}
					break;
				}
				case INTT_STATUS_ONCLICK: {
					bean = (CustomHeightBean) data;
					if (bean != null) {
						mScrollDownLayout.setMinOffset(0);
						mScrollDownLayout.setMaxOffset(bean.MaxOffset);
						mScrollDownLayout.setExitOffset(bean.ExitOffset);

					}
					mScrollDownLayout.setToMinOffset();
					break;
				}
				case ORDER_STATUS_CAHANGE: {
					if (MyAppcation.getMyAppcation().getUserBean() != null) {
						getOrderInfo();
					}
					getNetworkCoords();
					break;
				}
				case INIT_ORDER_STATUS: {
					bean = (CustomHeightBean) data;

					if (bean != null) {
						mScrollDownLayoutLongRent.setMaxOffset(bean.MaxOffset);
						mScrollDownLayoutLongRent.setExitOffset(bean.ExitOffset);
					}
					mScrollDownLayoutLongRent.setToMinOffset();
					break;
				}

				case SHOW_ORDER_STATUS: {
					mScrollDownLayoutLongRent.setToMinOffset();
					break;
				}
				case SUBSCRIBE_BIGCUSTOM_SUCCESS: {
					bean = (CustomHeightBean) data;
					DaKeHuYuYueBean daKeHuYuYueBean = (DaKeHuYuYueBean) bean.data;
					mBigCustomerOrderBean.type = ResponseBigCustomerOrder.SUBSCRIBE_CODE;
					mBigCustomerOrderBean.bean = daKeHuYuYueBean;
					setOrderFragment();
					mScrollDownLayout.setToExitOffset();
					break;
				}
				case START_TO_USE_CAR: {
					mDrawButton.setVisibility(View.GONE);
					break;
				}
				case CALLCLE_SUBSCRIBE_BIGCUSTOM: {
					mBigCustomerOrderBean.type = ResponseBigCustomerOrder.NO_ORDER_CODE;
					setOrderFragment();
					break;
				}

				case START_USE_BIGCUSTOM_CAR: {
					bean = (CustomHeightBean) data;
					mBigCustomerOrderBean.type = ResponseBigCustomerOrder.OODER_CODE;
					mBigCustomerOrderBean.bean = (InterFaceBigCustomerOrderBeanAble) bean.data;
					orderShow();
					break;
				}
				case STOP_USE_BIGCUSTOM_CAR: {
					mBigCustomerOrderBean.type = ResponseBigCustomerOrder.NO_ORDER_CODE;
					orderShow();
					break;
				}
				case CHANGE_TO_BIGCUSTOM_AND_COMMOM: {
					isBigCustomer = !isBigCustomer;
					mMainTopFragment.setBigCustomer(isBigCustomer);
					mDrawerLayout.closeDrawer(Gravity.LEFT);
					break;
				}
				default:
					break;
				}
			}
		};

		mDisssmissInterFace = new DisssmissInterFace() {

			@Override
			public void putError(VolleyError error) {
				if (promptDialog != null)
					promptDialog.dismiss();
			}
		};
	}

	public void initData() {
		mDrawButton.setVisibility(View.GONE);
		initOrderFragment();
		int time = MyAppcation.getMyAppcation().getMap_update_second();
		mTask = new TimeUtil(2 * time, time);
		if (mTask != null) {
			TimeListener timeListener = new TimeListener() {

				@Override
				public void timeOnTick(long time) {
					getNetworkCoords();
				}

				@Override
				public void timeFinish() {
					mTask.cancel();
					mTask.start();
				}
			};
			mTask.setTimeListener(timeListener);
			mTask.start();
		}
		promptDialog.show();
		getNetworkCoords();
		if (MyAppcation.getMyAppcation().getUserBean() != null) {
			getOrderInfo();
			getMessageId();
			getDriving_license_expireStatus(MyAppcation.getMyAppcation().getUserBean());
		}
		mMapOverlay = new MapOverlay(mAMap);
		mMapOverlay.setOnClusterClickListener(MainActivity.this);
		mMainLeftFragment = (MainLeftFragment) getSupportFragmentManager().findFragmentById(R.id.left_drawer);
		MyAppcation.getMyAppcation().addBaseInterFace(mMainLeftFragment);
		if (mMainLeftFragment != null) {
			mMainLeftFragment.setData();
		}

		if (Helper_SharedPreferences.get_bool_sp(CodeConstant.ISXINSHOU) == false) {// 新手引导
			guideDialog = new GuideDialog(this);
			guideDialog.show();
			Helper_SharedPreferences.set_bool_sp(CodeConstant.ISXINSHOU, true);
		}

		isFrom = getIntent().getIntExtra("isFrom", 0);
		switch (isFrom) {
		case 0:
			break;
		case 1: {
			TipDialog tipDialog = new TipDialog(this, "温馨提示", "您需要实名认证后才能用车，去认证?", new MyDialogButton() {

				@Override
				public void setTitle(int flag, String str) {
					intent = new Intent(MyAppcation.getMyAppcation(), AuthorizeActivity.class);
					intent.putExtra("state", -1);
					startActivity(intent);
				}
			});
			tipDialog.show();
			tipDialog.setRightText("认证");
			break;
		}
		default:
			break;
		}

		if (MyAppcation.getMyAppcation().isFirstInter) {
			getNoticeRequest();
		}
		/**
		 * 是否是由通知栏点击进去
		 */
		JpushNotifactionResponse bean = (JpushNotifactionResponse) getIntent().getSerializableExtra("bean");
		if (bean != null) {
			intent = new Intent(this, DialogActivity.class);
			intent.putExtra("bean", bean);
			startActivity(intent);
		}

		MainInterFaceAble mMainInterFaceAble = new MainInterFaceAble() {
			@Override
			public Object uIChange(int type, Object data) {
				switch (type) {
					case NAVIGATION:
						setFlag((int)data);
						break;
					case SHOW_LEFT: {
						if (MyAppcation.getMyAppcation().getUserBean() != null) {
							mDrawerLayout.openDrawer(Gravity.LEFT);
						} else {
							intent = new Intent(MyAppcation.getMyAppcation(), LoginActivity.class);
							startActivity(intent);
						}
						break;
					}
					case GET_LOCTION:
						if (MyAppcation.getMyAppcation().getLocation() != null) {
							LatLng latLng = new LatLng(MyAppcation.getMyAppcation().getLocation().getLatitude(), MyAppcation.getMyAppcation().getLocation().getLongitude());
							mAMap.moveCamera(CameraUpdateFactory.changeLatLng(latLng));
							mAMap.moveCamera(CameraUpdateFactory.zoomTo(CodeConstant.X));
						} else {
							startLocation();
							if (mShortList.size() == 0 || mLongList.size() == 0) {
								getNetworkCoords();
							}
						}
							break;
					case SHOW_DIALOG: {
						if (MyAppcation.getMyAppcation().getUserBean() != null) {
							PersonProblemDialog personProblemDialog = new PersonProblemDialog(MainActivity.this);
							personProblemDialog.show();
						} else {
							intent = new Intent(MyAppcation.getMyAppcation(), LoginActivity.class);
							startActivity(intent);
						}
						break;
					}
					case SCAN_CODE:
					if (MyAppcation.getMyAppcation().getUserBean() != null) {
						intent = new Intent(MyAppcation.getMyAppcation(), MipcaActivityCapture.class);
						if (flag_status == FLAG_SHORT_TIME || flag_status == FLAG_BIGCUSTOME) {
							intent.putExtra("flag", 0);
						} else {
							intent.putExtra("flag", 1);
						}
						startActivityForResult(intent, PileInfoFragment.SCANNIN_GREQUEST_CODE);
					} else {
						intent = new Intent(MyAppcation.getMyAppcation(), LoginActivity.class);
						startActivity(intent);
					}
						break;
					case FRESH_CODE:
						if (mBigCustomerCarList != null) {
							mBigCustomerCarList.clear();
						}
						getDaKeHuData();
						break;
				}
				return null;
			}
		};
		mMainTopFragment = (MainTopFragment) getSupportFragmentManager().findFragmentById(R.id.top_drawer);
		mMainTopFragment.setmMainInterFaceAble(mMainInterFaceAble);

		mMainBottomFragment = (MainBottomFragment) getSupportFragmentManager().findFragmentById(R.id.bottom_drawer);
		mMainBottomFragment.setmMainInterFaceAble(mMainInterFaceAble);
		mMainBottomFragment.setFreshIsVisable(View.INVISIBLE);
	}

	/**
	 * 判断驾照是否过期
	 *
	 * @param responseUserBean
	 */
	private void getDriving_license_expireStatus(ResponseUserBean responseUserBean) {

		if (responseUserBean.check_data_status == 1) {
			if (responseUserBean.driving_license_expire > 0) {
				final long time = responseUserBean.driving_license_expire - System.currentTimeMillis() / 1000;

				long minTime = 30 * 24 * 60 * 60;
				if (time < minTime) {
					RequestGetDriverLicenseReviewInfo requestBean = new RequestGetDriverLicenseReviewInfo();
					MyAppcation.getMyAppcation().getPostData(this, requestBean, new GetDataInterFace<String>() {

						@Override
						public void onResponse(String response) {

							if (!response.startsWith("[")) {
								final ResponseGetDriverLicenseReviewInfo bean = JSON.parseObject(response,
										ResponseGetDriverLicenseReviewInfo.class);
								String content = "";
								TipDialog tipDialog = new TipDialog(MainActivity.this, "温馨提示", content,
										new MyDialogButton() {

											@Override
											public void setTitle(int flag, String str) {
												intent = new Intent(getApplicationContext(),
														AuthorizeDriverActivity.class);
												intent.putExtra("bean", bean);
												startActivity(intent);
											}
										});

								switch (bean.status) {
								case ResponseGetDriverLicenseReviewInfo.NULL:

									if (time < 0) {
										content = "您的驾驶证已过期，请尽快更换。我们将暂时取消您的用车资格，谢谢配合！";
										tipDialog.show();
										tipDialog.setContent(content);
									} else if (time < 7 * 24 * 60 * 60) {
										content = "您的驾驶证有效期不足7天，请尽快更换。如驾驶证过期，将暂时取消您的用车资格。";
										tipDialog.show();
										tipDialog.setContent(content);
									} else {
										content = "您的驾驶证有效期不足30天，请尽快更换。以免影响您的用车。";
										tipDialog.show();
										tipDialog.setContent(content);
									}
									break;
								case ResponseGetDriverLicenseReviewInfo.STAY:

									break;
								case ResponseGetDriverLicenseReviewInfo.ALLOW:

									break;
								case ResponseGetDriverLicenseReviewInfo.REFUSE:
									content = "您提交的驾驶证未通过审核，请重新上传有效的驾驶证图片，谢谢！";
									tipDialog.show();
									tipDialog.setContent(content);
									break;

								default:
									break;
								}

							} else {
								String content = "";
								TipDialog tipDialog = new TipDialog(MainActivity.this, "温馨提示", content,
										new MyDialogButton() {

											@Override
											public void setTitle(int flag, String str) {
												intent = new Intent(getApplicationContext(),
														AuthorizeDriverActivity.class);
												startActivity(intent);
											}
										});

								if (time < 0) {
									content = "您的驾驶证已过期，请尽快更换。我们将暂时取消您的用车资格，谢谢配合！";
									tipDialog.show();
									tipDialog.setContent(content);
								} else if (time < 7 * 24 * 60 * 60) {
									content = "您的驾驶证有效期不足7天，请尽快更换。如驾驶证过期，将暂时取消您的用车资格。";
									tipDialog.show();
									tipDialog.setContent(content);
								} else {
									content = "您的驾驶证有效期不足30天，请尽快更换。以免影响您的用车。";
									tipDialog.show();
									tipDialog.setContent(content);
								}
							}
						}
					}, new DisssmissInterFace() {

						@Override
						public void putError(VolleyError error) {

							promptDialog.dismiss();
						}
					});

				}
			} else {
				MyAppcation.getMyAppcation().clearUserBean();
				intent = new Intent(getApplicationContext(), LoginActivity.class);
				startActivity(intent);
				finish();
			}
		}
	}

	/**
	 * 获取航展信息
	 */
	private void getNoticeRequest() {

		NoticeRequest requestBean = new NoticeRequest();
		MyAppcation.getMyAppcation().getPostData(this, requestBean, new GetDataInterFace<String>() {

			@Override
			public void onResponse(String response) {

				MyAppcation.getMyAppcation().isFirstInter = false;
				promptDialog.dismiss();
				BaseBeanResponse<String> baseBean = JSON.parseObject(response,
						new TypeReference<BaseBeanResponse<String>>() {
						});
				if (baseBean.errCode == 0) {
					final NoticeResponse bean = JSON.parseObject(baseBean.data, NoticeResponse.class);
					NoticeTipDialog noticeTipDialog = new NoticeTipDialog(MainActivity.this, bean,
							new MyDialogButton() {

								@Override
								public void setTitle(int flag, String str) {
									afterNoticeTipDialogOnclick(bean);
								}
							});
					noticeTipDialog.show();
				}

			}
		}, mDisssmissInterFace);
	}

	/**
	 * 点击航展dialog后的事件
	 */
	private void afterNoticeTipDialogOnclick(NoticeResponse bean) {
		if (bean.details_url == null || bean.details_url.equals("")) {
			switch (bean.messageType) {
			case 1: {
				intent = new Intent(getApplicationContext(), MessageDetailsActivity.class);
				intent.putExtra("id", bean.messageId + "");
				startActivity(intent);
				break;
			}
			case 2: {
				intent = new Intent(getApplicationContext(), ActivityListDetailsActivity.class);
				intent.putExtra("id", bean.messageId + "");
				startActivity(intent);
				break;
			}
			case 3: {
				intent = new Intent(getApplicationContext(), MyAssetDetailsActivity.class);
				intent.putExtra("id", bean.messageId + "");
				startActivity(intent);
				break;
			}
			default:
				break;
			}
		} else {
			intent = new Intent(MyAppcation.getMyAppcation(), ShowURLActivity.class);
			intent.putExtra("url", bean.details_url);
			intent.putExtra("title", bean.title);
			startActivity(intent);
		}
	}

	/**
	 * 开启定位
	 */
	public void startLocation() {
		if (mAMap != null) {

			MyLocationStyle myLocationStyle;
			myLocationStyle = new MyLocationStyle();//初始化定位蓝点样式类myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);//连续定位、且将视角移动到地图中心点，定位点依照设备方向旋转，并且会跟随设备移动。（1秒1次定位）如果不设置myLocationType，默认也会执行此种模式。
			myLocationStyle.interval(60 * 1000); //设置连续定位模式下的定位间隔，只在连续定位模式下生效，单次定位模式下不会生效。单位为毫秒。
			myLocationStyle.myLocationIcon(BitmapDescriptorFactory.fromResource(R.mipmap.daohang));
			myLocationStyle.strokeColor(0x00ffffff);
			myLocationStyle.radiusFillColor(0x00ffffff);
			mAMap.setMyLocationStyle(myLocationStyle);//设置定位蓝点的Style
			UiSettings mUiSettings = mAMap.getUiSettings();// 拿到地图工具类
			mUiSettings.setMyLocationButtonEnabled(false);//设置默认定位按钮是否显示，非必需设置。
			mUiSettings.setMyLocationButtonEnabled(false);// 设置默认定位按钮是否显示
			mUiSettings.setTiltGesturesEnabled(false);// 禁用倾斜手势。
			mUiSettings.setRotateGesturesEnabled(false);// 禁用旋转手势。
			mUiSettings.setZoomControlsEnabled(false);//隐藏加减号
			mAMap.setMyLocationEnabled(true);// 设置为true表示启动显示定位蓝点，false表示隐藏定位蓝点并不进行定位，默认是false。
			mAMap.setOnMyLocationChangeListener(this);// 设置定位监听
		}
	}

	/**
	 * 获取消息ID
	 */
	private void getMessageId() {

		Get_all_message_idRequest requestBean = new Get_all_message_idRequest();
		requestBean.system_message_id = 0;
		MyAppcation.getMyAppcation().getPostData(this, requestBean, new GetDataInterFace<String>() {

			@Override
			public void onResponse(String response) {

				ResponseAllMessageId bean1 = JSON.parseObject(response, ResponseAllMessageId.class);
				Helper_SharedPreferences.set_obj_sp(CodeConstant.messageServer, bean1);
				ResponseAllMessageId bean2 = (ResponseAllMessageId) Helper_SharedPreferences
						.get_obj_sp(CodeConstant.messageClient);
				setMessage(bean1, bean2);
			}
		}, mDisssmissInterFace);

	}

	/**
	 *
	 * @param messageServerBean
	 *            服务器获取的bean
	 * @param messageClientBean
	 *            客户端保存的bean
	 */
	public void setMessage(ResponseAllMessageId messageServerBean, ResponseAllMessageId messageClientBean) {

		int server_max_id = messageServerBean.activity_max_id + messageServerBean.system_message_max_id
				+ messageServerBean.user_message_max_id;
		if (messageClientBean == null && server_max_id > 0) {
			mMainBottomFragment.setMessageIcon(R.mipmap.home_icon_news_red);
//			message.setImageResource(R.mipmap.iocn10);
		} else {
			int client_max_id = messageClientBean.activity_max_id + messageClientBean.system_message_max_id
					+ messageClientBean.user_message_max_id;
			if (client_max_id < server_max_id) {
				mMainBottomFragment.setMessageIcon(R.mipmap.home_icon_news_red);;
			} else {
				mMainBottomFragment.setMessageIcon(R.mipmap.home_icon_news);
			}
		}
	}

	/**
	 * 拉取单个网点车辆列表信息
	 */
	private void getNetworkCarsInfo() {

		Get_network_car_list_infoRequest requestBean = new Get_network_car_list_infoRequest();
		requestBean.networkId = item.getNetworkId();
		promptDialog.show();
		MyAppcation.getMyAppcation().getPostData(this, requestBean, new GetDataInterFace<String>() {

			@Override
			public void onResponse(String response) {

				promptDialog.dismiss();
				List<CarInfoBean> list = JSON.parseArray(response, CarInfoBean.class);
				if (list != null && list.size() != 0) {
					if (fragmentList != null) {
						fragmentList.clear();
					} else {
						fragmentList = new ArrayList<Fragment>();
					}
					if (mShortCarList != null) {
						mShortCarList.clear();
					} else {
						mShortCarList = new ArrayList<ClusterItem>();
					}
					list = SwapData.getNewListData(list);
					boolean isRent = (mShortTimeOrderBean.orderType == ResponseShortTimeOrder.OODER_CODE);
					for (int i = 0, size = list.size(); i < size; i++) {
						ShortTimeCarInfoFragment carInfoFrament = ShortTimeCarInfoFragment.newInstance(list.get(i),
								item, isRent);
						mShortCarList.add(list.get(i));
						fragmentList.add(carInfoFrament);
					}
					mMapOverlay.setMClustersCar(mShortCarList);
					setViewPageAdapter();
				} else {
					showNoCarInfoFrament();
				}

			}
		}, mDisssmissInterFace);
	}

	/**
	 * viewpage设置新的适配器
	 *
	 */
	private void setViewPageAdapter() {

		adapter = new FragmentStatePagerAdapter(getSupportFragmentManager(), fragmentList);
		mViewPage.setAdapter(adapter);
		mViewPage.setCurrentItem(0);
		mViewPage.setOffscreenPageLimit(5);
		adapter.notifyDataSetChanged();
		LayoutParams lp = (LayoutParams) mViewPage.getLayoutParams();
		int margin = getResources().getDimensionPixelSize(R.dimen.dp15);
		if (fragmentList.size() > 1) {
			margin = getResources().getDimensionPixelSize(R.dimen.dp30);
			mViewPage.setPageTransformer(true, new ZoomOutPageTransformer());
		}
		lp.setMargins(margin, 0, margin, 0);
		mViewPage.setLayoutParams(lp);

		if (mShortTimeOrderBean.orderType == ResponseShortTimeOrder.OODER_CODE && flag_status == FLAG_SHORT_TIME
				&& !(fragmentList.get(0) instanceof ShortTimeRentcarFragment)) {
			iv_using_car.setVisibility(View.VISIBLE);
		} else {
			iv_using_car.setVisibility(View.GONE);
		}
	}

	/**
	 * 获取预约车辆信息或订单信息
	 */

	private void getOrderInfo() {

		Get_now_car_orderRequest requestBean = new Get_now_car_orderRequest();
		MyAppcation.getMyAppcation().getPostData(this, requestBean, new GetDataInterFace<String>() {

			@Override
			public void onResponse(String response) {

				promptDialog.dismiss();
				mShortTimeOrderBean = JSON.parseObject(response, ResponseShortTimeOrder.class);
				switch (mShortTimeOrderBean.orderType) {
				case ResponseShortTimeOrder.NO_ORDER_CODE:
					Helper_SharedPreferences.clear_sharePref("FENSHI_STOP_TIME");
					break;
				case ResponseShortTimeOrder.SUBSCRIBE_CODE:
					SubscribeOrderInfo subscribeOrderInfo = JSON.parseObject(mShortTimeOrderBean.userOrderInfo,
							SubscribeOrderInfo.class);
					mShortTimeOrderBean.mShortTimeBean = subscribeOrderInfo;
					/**
					 * 保存本地计时器时间,fragmet onResume每次取一次
					 */
					Helper_SharedPreferences.set_long_sp("FENSHI_STOP_TIME", System.currentTimeMillis() / 1000
							+ subscribeOrderInfo.subscribeOrderExpire);
					break;
				case ResponseShortTimeOrder.OODER_CODE:
					ResponseAppUserOrder app_add_user_orderResponse = JSON.parseObject(
							mShortTimeOrderBean.userOrderInfo, ResponseAppUserOrder.class);
					mShortTimeOrderBean.mShortTimeBean = app_add_user_orderResponse;
					Helper_SharedPreferences.clear_sharePref("FENSHI_STOP_TIME");
					break;
				default:
					break;
				}
				setPage();
				if (mShortTimeOrderBean.mLongrentSubscribe != null) {
					mLongRentOrderBean.type = ResponseLongRentOrder.SUBSCRIBE_CODE;
					mLongRentOrderBean.bean = mShortTimeOrderBean.mLongrentSubscribe;
					if (isFirstInter && flag_status == FLAG_SHORT_TIME) {
						String tip = "";
						if (mLongRentOrderBean.bean.getPay_finish_time() == 0) {
							tip = "您预约的车辆未完成支付";
						} else {
							tip = "已预约车辆  请到预约网点取车";
						}
						LongRentTipDialog longRentTipDialog = new LongRentTipDialog(MainActivity.this, "提示", tip,
								new MyDialogButton() {

									@Override
									public void setTitle(int flag, String str) {
										getData(mLongRentOrderBean.bean.getSubscribe_network_id());
									}
								});
						longRentTipDialog.show();
					}
				}
				isFirstInter = false;
			}
		}, mDisssmissInterFace);
	}

	/**
	 * 重新加载订单信息(包括)
	 */
	protected void setPage() {
		setOrderFragment();
		orderShow();
	}

	/**
	 * 拉去所有网点
	 */

	private void getNetworkCoords() {

		final Get_all_network_coordsRequest requestBean = new Get_all_network_coordsRequest();
		requestBean.times = Helper_SharedPreferences.get_int_sp(CodeConstant.Get_all_network_coords_time);
		MyAppcation.getMyAppcation().getPostData(this, requestBean, new GetDataInterFace<String>() {

			@Override
			public void onResponse(String response) {

				promptDialog.dismiss();
				ResponseAllNetworkCoords base1 = JSON.parseObject(response, ResponseAllNetworkCoords.class);
				Helper_SharedPreferences.set_int_sp(CodeConstant.Get_all_network_coords_time, base1.times);
				if (base1.is_update == 1) {
					MyCache.getMyCache().putCache(requestBean.getUrl(), JSON.toJSONString(base1.points));
					setNetworkData(base1.points);
				} else {
					if (mShortList.size() == 0 || mLongList.size() == 0) {
						String json = MyCache.getMyCache().getCache(requestBean.getUrl());
						if (json != null && !json.equals("")) {
							List<Point> listCache = JSON.parseArray(json, Point.class);
							setNetworkData(listCache);
						} else {
							Helper_SharedPreferences.set_int_sp(CodeConstant.Get_all_network_coords_time, 0);
						}
					}
				}

			}
		}, new DisssmissInterFace() {

			@Override
			public void putError(VolleyError error) {
				promptDialog.dismiss();
				if (mLongList.size() == 0 || mShortList.size() == 0) {
					String json = MyCache.getMyCache().getCache(requestBean.getUrl());
					if (json != null && !json.equals("")) {
						List<Point> listCache = JSON.parseArray(json, Point.class);
						setNetworkData(listCache);
					}
				}
			}
		});
	}

	/**
	 * 设置地图上网点数据
	 *
	 * @param points
	 */
	public void setNetworkData(List<Point> points) {

		mLongList.clear();
		mShortList.clear();
		for (Point bean : points) {
			switch (bean.network_rent_type) {
			case Point.TYPE_OLD:
				if (bean.handle_long_rent == 1) {
					mLongList.add(bean);
				}
				mShortList.add(bean);
				break;
			case Point.TYPE_SHORT:
				mShortList.add(bean);
				break;
			case Point.TYPE_LONG:
				mLongList.add(bean);
				break;
			case Point.TYPE_SHORT_LONG:
				mLongList.add(bean);
				mShortList.add(bean);
				break;
			default:
				if (bean.handle_long_rent == 1) {
					mLongList.add(bean);
				}
				mShortList.add(bean);
				break;
			}
		}
		if (flag_status == FLAG_SHORT_TIME) {
			setPoints(mShortList);
		} else if (flag_status == FLAG__LONG_RENT) {
			setPoints(mLongList);
		}
	}

	/**
	 * 根据网点数据往地图添加覆盖物
	 */

	protected void setPoints(List<ClusterItem> points) {

		try {
			mMapOverlay.setMarkerListall(points, flag_status);
			setView();
			switch (flag_status) {
			case FLAG_SHORT_TIME:
				if (mShortTimeOrderBean.orderType != ResponseShortTimeOrder.OODER_CODE) {
					mMapOverlay.setMyCar(null);
				}
				break;
			case FLAG__LONG_RENT:
				if (mLongRentOrderBean.type != ResponseLongRentOrder.OODER_CODE) {
					mMapOverlay.setMyCar(null);
				}
				break;
			case FLAG_PILE:
				mMapOverlay.setMyCar(null);
				break;
			case FLAG_BIGCUSTOME:
				if (mBigCustomerOrderBean.type != ResponseBigCustomerOrder.OODER_CODE) {
					mMapOverlay.setMyCar(null);
				}
				break;
			default:
				break;
			}

		} catch (Exception e) {
			MyException.printStackTrace(e);
		}

	}

	public void initEvent() {

		mDrawButton.setOnClickListener(this);
//		right.setOnClickListener(this);
//		left.setOnClickListener(this);
//		text.get(FLAG_SHORT_TIME).setOnClickListener(this);
//		text.get(FLAG__LONG_RENT).setOnClickListener(this);
//		text.get(FLAG_PILE).setOnClickListener(this);
//		text.get(FLAG_BIGCUSTOME).setOnClickListener(this);
//		message.setOnClickListener(this);
		iv_using_car.setOnClickListener(this);
		mViewPage.addOnPageChangeListener(new MyViewPager.MyOnPageChangeListener() {

			@Override
			public void onPageSelected(int arg0) {

				if (mShortCarList != null && mShortCarList.size() > arg0 && flag_status == FLAG_SHORT_TIME) {
					mMapOverlay.setItemMClustersCar(arg0);
				}
				if (mBigCustomerCarList != null && mBigCustomerCarList.size() > arg0 && flag_status == FLAG_BIGCUSTOME) {
					mMapOverlay.setItemMClustersCar(arg0);
				}
			}
		});
		mScrollDownLayout.setOnScrollChangedListener(this);

	}

	/**
	 * 网点marker点击事件
	 */
	@Override
	public void onMarkerClick(ClusterItem item) {
		this.item = item;
		switch (flag_status) {
		case FLAG_SHORT_TIME: {
			if (mShortTimeOrderBean.orderType != ResponseShortTimeOrder.SUBSCRIBE_CODE) {
				if (item.getCars(FLAG_SHORT_TIME) != 0) {// 网店车辆不为0
					getNetworkCarsInfo();
				} else {
					showNoCarInfoFrament();
				}
			}
			// } else if (mShortTimeOrderBean.orderType ==
			// ResponseShortTimeOrder.OODER_CODE) {
			// orderShow();
			// }
			break;
		}
		case FLAG__LONG_RENT:
			getNetworkInfo(item);
			break;
		case FLAG_PILE:
			if (start_chargeBean == null) {
				charging_pile_get_network_infoRequest(item);
			} else {
				setPileOrder(start_chargeBean);
			}
			break;

		default:
			break;
		}
	}

	/**
	 * 小汽车marker点击事件
	 */
	@Override
	public void onCarMarkerClick(ClusterItem cluster, int item) {
		if (flag_status == FLAG_BIGCUSTOME && mBigCustomerOrderBean.type == ResponseBigCustomerOrder.OODER_CODE) {

		} else {

			if ((flag_status == FLAG_SHORT_TIME && mShortTimeOrderBean.orderType == ResponseShortTimeOrder.NO_ORDER_CODE)
					|| (flag_status == FLAG_BIGCUSTOME && mBigCustomerOrderBean.type == ResponseBigCustomerOrder.NO_ORDER_CODE)) {

				if (mViewPage != null && fragmentList != null && fragmentList.size() > 0 && item < fragmentList.size()) {
					mViewPage.setCurrentItem(item, false);
					mScrollDownLayout.setToMinOffset();

				} else {
					Tools.showMessage("此车辆不可用");
				}
			}

		}
	}

	/**
	 * 显示无车辆网店信息
	 */
	private void showNoCarInfoFrament() {
		NoCarInfoFragment carInfoFrament = NoCarInfoFragment.newInstance(item.getName());
		mMapOverlay.setMClustersCar(null);
		if (fragmentList != null) {
			fragmentList.clear();
		} else {
			fragmentList = new ArrayList<Fragment>();
		}
		fragmentList.add(carInfoFrament);
		setViewPageAdapter();
	}

	/**
	 * 获取充电桩网点信息
	 *
	 * @param clusterItem
	 */
	private void charging_pile_get_network_infoRequest(final ClusterItem clusterItem) {

		RequestPileNetworkInfo requestBean = new RequestPileNetworkInfo();
		requestBean.pileNetworkId = item.getNetworkId();
		promptDialog.show();
		MyAppcation.getMyAppcation().getPostData(this, requestBean, new GetDataInterFace<String>() {

			@Override
			public void onResponse(String response) {

				promptDialog.dismiss();
				ResponsePileNetworkInfo bean = JSON.parseObject(response, ResponsePileNetworkInfo.class);
				PileInfoFragment pileInfoFrament = PileInfoFragment.newInstance(clusterItem, item, bean);
				if (fragmentList != null) {
					fragmentList.clear();
				} else {
					fragmentList = new ArrayList<Fragment>();
				}
				fragmentList.add(pileInfoFrament);
				setViewPageAdapter();
			}
		}, mDisssmissInterFace);

	}

	/**
	 * 获取单个网点信息
	 *
	 * @param item
	 */
	private void getNetworkInfo(final ClusterItem item) {
		Get_network_infoRequest requestBean = new Get_network_infoRequest();
		requestBean.networkId = item.getNetworkId();
		promptDialog.show();
		MyAppcation.getMyAppcation().getPostData(this, requestBean, new GetDataInterFace<String>() {

			@Override
			public void onResponse(String response) {
				promptDialog.dismiss();
				ResponsePlieNetworkInfo base = JSON.parseObject(response, ResponsePlieNetworkInfo.class);
				LongTimeCarInfoFragment carInfoFrament = LongTimeCarInfoFragment.newInstance(mLongRentOrderBean, item,
						base);
				if (fragmentList != null) {
					fragmentList.clear();
				} else {
					fragmentList = new ArrayList<Fragment>();
				}
				fragmentList.add(carInfoFrament);
				setViewPageAdapter();
			}
		}, mDisssmissInterFace);
	}

	@Override
	protected void onResume() {
		super.onResume();
		if (mMapView != null) {
			mMapView.onResume();
		}
		if (mTask != null) {
			mTask.start();
		}
	}

	@Override
	protected void onPause() {
		super.onPause();
		if (mMapView != null) {
			mMapView.onPause();
		}
		if (mTask != null) {
			mTask.cancel();
		}

	}


	@Override
	public void onMyLocationChange(Location location) {

		if(location.getLatitude()!=0) {
			LatLng latLng = new LatLng(location.getLatitude(),location.getLongitude());
			if (MyAppcation.getMyAppcation().getLocation() == null) {
				MyAppcation.getMyAppcation().setLocation(location);
				this.mAMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 12));
				setView();
			} else {
				MyAppcation.getMyAppcation().setLocation(location);
			}
		}
	}


	/**
	 * 设置一个网点与定位在地图上显示
	 */
	private void setView() {

		if (isFirst && MyAppcation.getMyAppcation().getLocation() != null && mShortList != null) {
			isFirst = false;
			Builder builder = new Builder();
			int size = mShortList.size();
			float min = AMapUtils.calculateLineDistance(MyAppcation.getMyAppcation().getMyLocation(), mShortList.get(0)
					.getLatLng());
			int x = 0;
			for (int i = 0; i < size; i++) {
				if ((min >= AMapUtils.calculateLineDistance(MyAppcation.getMyAppcation().getMyLocation(), mShortList
						.get(i).getLatLng()))) {
					x = i;
					min = AMapUtils.calculateLineDistance(MyAppcation.getMyAppcation().getMyLocation(),
							mShortList.get(i).getLatLng());
				}
			}
			builder.include(mShortList.get(x).getLatLng());
			builder.include(MyAppcation.getMyAppcation().getMyLocation());
			LatLngBounds bounds = builder.build();
			mAMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 200));
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {

		super.onActivityResult(requestCode, resultCode, data);
		switch (resultCode) {
		case CodeConstant.HCActivity: // 还车
			mShortTimeOrderBean.orderType = ResponseShortTimeOrder.NO_ORDER_CODE;
			mScrollDownLayout.setToExitOffset();
			if (MyAppcation.getMyAppcation().getUserBean() != null) {
				getOrderInfo();
			}

			getNetworkCoords();
			break;

		case CodeConstant.AddressCode:// 地址搜索
			if (data != null) {
				ResponseSearchHistory t = (ResponseSearchHistory) data.getSerializableExtra("bean");
				mMapOverlay.addSingleClusterItem(t);
				mAMap.animateCamera(CameraUpdateFactory.changeLatLng(t.getLatLng()));
			}
			break;

		case RESULT_OK:// 扫码回调
			switch (requestCode) {
			case PileInfoFragment.SCANNIN_GREQUEST_CODE:
				Bundle bundle = data.getExtras();
				String result = bundle.getString("result");
				if (result.startsWith(CodeConstant.HTML) || result.startsWith(CodeConstant.THTML)) {
					JSONObject htmlResponse = StringTools.getObject(result);
					try {
						if (flag_status != FLAG_PILE) {// 扫码租车
							if (htmlResponse.getInt("t") == 1) {
								Qr_carRequest requestBean = new Qr_carRequest();
								requestBean.car_id = htmlResponse.getInt("y");
								GetDataInterFace<String> listen = new GetDataInterFace<String>() {
									@Override
									public void onResponse(String response) {
										promptDialog.dismiss();
										List<CarInfoBean> carInfoBean = JSON.parseArray(response, CarInfoBean.class);
										if (fragmentList != null) {
											fragmentList.clear();
										} else {
											fragmentList = new ArrayList<Fragment>();
										}
										if (mShortCarList != null) {
											mShortCarList.clear();
										} else {
											mShortCarList = new ArrayList<ClusterItem>();
										}
										ShortTimeCarInfoFragment carInfoFrament = ShortTimeCarInfoFragment.newInstance(
												carInfoBean.get(0), null, false);
										mShortCarList.addAll(carInfoBean);
										fragmentList.add(carInfoFrament);
										mMapOverlay.setMClustersCar(mShortCarList);
										setViewPageAdapter();
									}
								};

								if (flag_status == FLAG_BIGCUSTOME) {
									get_big_customer_invite_info(requestBean, listen);
								} else {
									promptDialog.show();
									MyAppcation.getMyAppcation().getPostData(this, requestBean, listen,
											mDisssmissInterFace);
								}
							} else {
								Tools.showMessage("请切换至扫码充电");
							}
						} else {
							if (htmlResponse.getInt("t") == 2) {

								String[] sourse = htmlResponse.getString("y").split("#");
								if (sourse == null || sourse.length < 2)
									return;
								final String y = sourse[1];
								DissMissable mDissMissable = new DissMissable() {

									@Override
									public void getPsw(String pwd) {
										Start_chargeRequest start_chargeRequest = new Start_chargeRequest();
										start_chargeRequest.chargeType = 1;
										start_chargeRequest.connectorId = y;
										start_chargeRequest.userPin = pwd;
										promptDialog.show();
										GetDataInterFace<String> listener = new GetDataInterFace<String>() {

											@Override
											public void onResponse(String response) {
												promptDialog.dismiss();
												ResponseStartCharge start_chargeBean = JSON.parseObject(response,
														ResponseStartCharge.class);
												setPileOrder(start_chargeBean);
											}
										};

										MyAppcation.getMyAppcation().getPostData(this, start_chargeRequest, listener,
												new DisssmissInterFace() {

													@Override
													public void putError(VolleyError error) {
														promptDialog.dismiss();
													}
												});
									}
								};

								PilePasswordDialog passwordDialog = new PilePasswordDialog(this, mDissMissable);
								passwordDialog.show();

							} else {
								Tools.showMessage("请切换至扫码租车");
							}

						}
					} catch (JSONException e) {
						e.printStackTrace();
						Tools.showMessage("二维码错误");
					}
				} else {
					Tools.showMessage("二维码错误");
				}
				break;

			default:
				break;
			}
			break;
		default:
			break;
		}
	}

	/**
	 * 获取大客户邀请信息
	 *
	 * @param requestBean2
	 * @param listener
	 */
	public void get_big_customer_invite_info(final Qr_carRequest requestBean2, final GetDataInterFace<String> listener) {
		promptDialog.show();
		Get_big_customer_invite_infoRequest requestBean = new Get_big_customer_invite_infoRequest();
		MyAppcation.getMyAppcation().getPostData(this, requestBean, new GetDataInterFace<String>() {

			@Override
			public void onResponse(String response) {

				ResponseBigCustomerInviteInfo bean = JSON.parseObject(response, ResponseBigCustomerInviteInfo.class);
				requestBean2.bigCustomerId = bean.big_customer_id;
				MyAppcation.getMyAppcation()
						.getPostData(MainActivity.this, requestBean2, listener, mDisssmissInterFace);

			}
		}, mDisssmissInterFace);
	}

	@Override
	public void onClick(View arg0) {

		switch (arg0.getId()) {
		case R.id.message: {
			if (MyAppcation.getMyAppcation().getUserBean() != null) {
				intent = new Intent(MyAppcation.getMyAppcation(), MessageActivity.class);
				startActivity(intent);
			} else {
				intent = new Intent(MyAppcation.getMyAppcation(), LoginActivity.class);
				startActivity(intent);
			}
			break;
		}

		case R.id.iv_using_car: {
			setPage();
			break;
		}
		case R.id.button: {
			if (mShortTimeOrderBean.orderType == ResponseShortTimeOrder.SUBSCRIBE_CODE
					&& flag_status == FLAG_SHORT_TIME) {
				mShortTimeSubscribeFrament.startUser();
			}
			if (mBigCustomerOrderBean.type == ResponseBigCustomerOrder.SUBSCRIBE_CODE && flag_status == FLAG_BIGCUSTOME) {
				mBigCustomerSubscribeFrament.startUser();
			}
			break;
		}
		default:
			break;
		}
	}

	/**
	 * 获取大客户车辆数据
	 */
	private void getDaKeHuData() {

		if (mBigCustomerOrderBean != null && mBigCustomerOrderBean.type == ResponseBigCustomerOrder.NO_ORDER_CODE
				&& mBigCustomerCarList != null && mBigCustomerCarList.size() > 0) {
			if (fragmentList != null) {
				fragmentList.clear();
			} else {
				fragmentList = new ArrayList<Fragment>();
			}
			for (int i = 0, size = mBigCustomerCarList.size(); i < size; i++) {
				BigCustomerCarInfoFragment carInfoFrament = BigCustomerCarInfoFragment.newInstance(mBigCustomerCarList
						.get(i));
				fragmentList.add(carInfoFrament);
			}
			mMapOverlay.setMClustersCar(mBigCustomerCarList);
			setViewPageAdapter();
		} else {
			Get_car_list_Request requestBean = new Get_car_list_Request();

			mMainBottomFragment.startAnimation();
			promptDialog.show();
			MyAppcation.getMyAppcation().getPostData(this, requestBean, new GetDataInterFace<String>() {

				@Override
				public void onResponse(String response) {

					promptDialog.dismiss();
					mMainBottomFragment.clearAnimation();
					mMainBottomFragment.setFreshIsVisable(View.INVISIBLE);
					ResponseCarList get_car_list_Response = JSON.parseObject(response, ResponseCarList.class);
					new Handler().postDelayed(new Runnable() {

						@Override
						public void run() {
							if (flag_status == FLAG_BIGCUSTOME) {
								mMainBottomFragment.setFreshIsVisable(View.VISIBLE);
							}
						}
					}, 5000);
					if (get_car_list_Response.list != null && get_car_list_Response.list.size() != 0) {
						if (mBigCustomerCarList != null) {
							mBigCustomerCarList.clear();
						} else {
							mBigCustomerCarList = new ArrayList<ClusterItem>();
						}
						get_car_list_Response.list = SwapData.getNewListData(get_car_list_Response.list);
						mBigCustomerCarList.addAll(get_car_list_Response.list);
						mMapOverlay.setMClustersCar(mBigCustomerCarList);

						if (mBigCustomerOrderBean.type == ResponseBigCustomerOrder.NO_ORDER_CODE) {
							if (fragmentList != null) {
								fragmentList.clear();
							} else {
								fragmentList = new ArrayList<Fragment>();
							}
							for (int i = 0, size = get_car_list_Response.list.size(); i < size; i++) {
								BigCustomerCarInfoFragment carInfoFrament = BigCustomerCarInfoFragment
										.newInstance(get_car_list_Response.list.get(i));
								fragmentList.add(carInfoFrament);
							}
							setViewPageAdapter();
						}
					} else {
						Tools.showMessage("暂无车辆");
					}
				}
			}, new DisssmissInterFace() {

				@Override
				public void putError(VolleyError error) {
					if (promptDialog != null) {
						promptDialog.dismiss();
					}
					mMainBottomFragment.clearAnimation();
				}
			});
		}
	}

	/**
	 * 获取长租订单信息
	 */
	private void getLongRentOrderInfo() {

		Get_longrent_order_infoRequest requestBean = new Get_longrent_order_infoRequest();
		MyAppcation.getMyAppcation().getPostData(this, requestBean, new GetDataInterFace<String>() {

			@Override
			public void onResponse(String response) {

				promptDialog.dismiss();
				mLongRentOrderBean = JSON.parseObject(response, ResponseLongRentOrder.class);
				if (mLongRentOrderBean != null) {
					switch (mLongRentOrderBean.type) {
					case ResponseLongRentOrder.NO_ORDER_CODE:
						orderShow();
						setOrderFragment();
						break;
					case ResponseLongRentOrder.SUBSCRIBE_CODE:
						mLongRentOrderBean.bean = JSON
								.parseObject(mLongRentOrderBean.data, LongRentSubscribeBean.class);
						setOrderFragment();
						break;
					case ResponseLongRentOrder.OODER_CODE:
						mLongRentOrderBean.bean = JSON.parseObject(mLongRentOrderBean.data, LongRentOrderBean.class);
						setOrderFragment();
						break;
					default:
						break;
					}
				} else {
					mLongRentOrderBean = new ResponseLongRentOrder();
					setOrderFragment();
				}

			}
		}, mDisssmissInterFace);

	}

	/**
	 * 获取车型系列
	 */
	private void getData(String network_id) {
		Get_network_car_genre_listRequest requestBean = new Get_network_car_genre_listRequest();
		requestBean.network_id = network_id;
		promptDialog.show();
		MyAppcation.getMyAppcation().getPostData(this, requestBean, new GetDataInterFace<String>() {

			@Override
			public void onResponse(String response) {
				promptDialog.dismiss();
				Get_network_car_genre_listResponse bean = JSON.parseObject(response,
						Get_network_car_genre_listResponse.class);
				if (bean.carGenreList == null || bean.carGenreList.size() == 0) {
					Tools.showMessage("该网点暂无车型");
				} else {
					Intent intent = new Intent(MyAppcation.getMyAppcation(), LongRentOrderYuyueActivity.class);
					intent.putExtra("bean", JSON.toJSONString(bean));
					intent.putExtra("JSONString", JSON.toJSONString(mLongRentOrderBean.bean));
					startActivity(intent);
				}
			}
		}, mDisssmissInterFace);
	}

	/**
	 * 获取大客户订单信息
	 */
	private void getBigCustomerOrder() {

		promptDialog.show();
		Big_customer_get_user_car_orderRequest requestBean = new Big_customer_get_user_car_orderRequest();
		MyAppcation.getMyAppcation().getPostData(this, requestBean, new GetDataInterFace<String>() {

			@Override
			public void onResponse(String response) {

				promptDialog.dismiss();
				mBigCustomerOrderBean = JSON.parseObject(response, ResponseBigCustomerOrder.class);
				if (mBigCustomerOrderBean.type == ResponseBigCustomerOrder.SUBSCRIBE_CODE) {
					DaKeHuYuYueBean daKeHuYuYueBean = JSON.parseObject(mBigCustomerOrderBean.content,
							DaKeHuYuYueBean.class);
					mBigCustomerOrderBean.bean = daKeHuYuYueBean;

				} else if (mBigCustomerOrderBean.type == ResponseBigCustomerOrder.OODER_CODE) {
					BigCustomerOrderBean daKeHuOrderBean = JSON.parseObject(mBigCustomerOrderBean.content,
							BigCustomerOrderBean.class);
					mBigCustomerOrderBean.bean = daKeHuOrderBean;

				} else {
					getDaKeHuData();
				}
				setPage();

			}
		}, new DisssmissInterFace() {

			@Override
			public void putError(VolleyError error) {
				promptDialog.dismiss();
				getDaKeHuData();
				setPage();
			}
		});
	}

	/**
	 * 订单是租车订单，底部viewpage控制
	 */

	protected void orderShow() {
		if ((mShortTimeOrderBean.orderType == ResponseShortTimeOrder.OODER_CODE && flag_status == FLAG_SHORT_TIME)
				|| (mBigCustomerOrderBean.type == ResponseBigCustomerOrder.OODER_CODE && flag_status == FLAG_BIGCUSTOME)) {
			Fragment carInfoFrament;
			if (flag_status == FLAG_SHORT_TIME) {
				if (fragmentList.size() > 0 && fragmentList.get(0) instanceof ShortTimeRentcarFragment) {
					mScrollDownLayout.setToMinOffset();
				} else {
					if (fragmentList.size() > 0)
						fragmentList.clear();
					carInfoFrament = new ShortTimeRentcarFragment(mShortTimeOrderBean.mShortTimeBean);
					fragmentList.add(carInfoFrament);
					setViewPageAdapter();
				}
			} else {

				if (fragmentList.size() > 0 && fragmentList.get(0) instanceof BigCustomerRentcarFragment) {
					mScrollDownLayout.setToMinOffset();
				} else {
					if (fragmentList.size() > 0)
						fragmentList.clear();
					carInfoFrament = BigCustomerRentcarFragment.newInstance(mBigCustomerOrderBean.bean);
					fragmentList.add(carInfoFrament);
					setViewPageAdapter();
				}
			}

		} else {
			mScrollDownLayout.setToExitOffset();

		}
		setSaoMaViSible();
	}

	/**
	 * 初始化预约页面（大客户与分时）,以及长租预约和长租用车
	 */

	private void initOrderFragment() {

		mShortTimeOrderBean = new ResponseShortTimeOrder();
		mBigCustomerOrderBean = new ResponseBigCustomerOrder();
		mLongRentOrderBean = new ResponseLongRentOrder();
		FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
		if (mBigCustomerSubscribeFrament == null) {
			mBigCustomerSubscribeFrament = BigCustomerSubscribeFragment.newInstance(mBigCustomerOrderBean.bean);
		}
		transaction.add(R.id.yuyue, mBigCustomerSubscribeFrament);
		transaction.hide(mBigCustomerSubscribeFrament);
		if (mShortTimeSubscribeFrament == null) {
			mShortTimeSubscribeFrament = ShortTimeSubscribeFragment.newInstance(mShortTimeOrderBean.mShortTimeBean);
		}
		transaction.add(R.id.yuyue, mShortTimeSubscribeFrament);
		transaction.hide(mShortTimeSubscribeFrament);
		if (mLongTimeSubscribeFrament == null) {
			mLongTimeSubscribeFrament = LongTimeSubscribeFragment.newInstance(mLongRentOrderBean.bean);
		}
		transaction.add(R.id.frameLayout, mLongTimeSubscribeFrament);
		transaction.hide(mLongTimeSubscribeFrament);
		if (mLongTimeRentCarFrament == null) {
			mLongTimeRentCarFrament = LongTimeRentCarFragment.newInstance(mLongRentOrderBean.bean);
		}
		transaction.add(R.id.frameLayout, mLongTimeRentCarFrament);
		transaction.hide(mLongTimeRentCarFrament);
		transaction.commitAllowingStateLoss();
	}

	@Override
	protected void onDestroy() {
		if (mMapView != null) {
			mMapView.onDestroy();
		}
		if (mTask != null) {
			mTask.cancel();
		}
		if (isInit) {
			FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
			transaction.remove(mLongTimeSubscribeFrament);
			transaction.remove(mLongTimeRentCarFrament);
			transaction.remove(mShortTimeSubscribeFrament);
			transaction.remove(mBigCustomerSubscribeFrament);
			transaction.commitAllowingStateLoss();

			MyAppcation.getMyAppcation().reMoveBaseInterFace(mMainLeftFragment);
			mMainLeftFragment = null;
			mLongTimeSubscribeFrament = null;
			mLongTimeRentCarFrament = null;
			mShortTimeSubscribeFrament = null;
			mBigCustomerSubscribeFrament = null;
			mainActivityInterFace = null;
		}
		if (guideDialog != null) {
			guideDialog.dismiss();
		}
		super.onDestroy();
	}

	/**
	 * 根据订单状态，设置相应的fragment显示与隐藏
	 */
	private void setOrderFragment() {

		mDrawButton.setVisibility(View.GONE);
		switch (flag_status) {
		case FLAG_SHORT_TIME: {
			switch (mShortTimeOrderBean.orderType) {
			case ResponseShortTimeOrder.NO_ORDER_CODE:
				showOrderFragment(null);
				break;
			case ResponseShortTimeOrder.SUBSCRIBE_CODE:
				mDrawButton.setVisibility(View.VISIBLE);
				mShortTimeSubscribeFrament.setData(mShortTimeOrderBean.mShortTimeBean);
				showOrderFragment(mShortTimeSubscribeFrament);
				break;
			case ResponseShortTimeOrder.OODER_CODE:
				showOrderFragment(null);
				break;
			default:
				break;
			}

			break;
		}
		case FLAG__LONG_RENT: {
			mDrawButton.setVisibility(View.GONE);
			switch (mLongRentOrderBean.type) {
			case ResponseLongRentOrder.NO_ORDER_CODE:
				showOrderFragment(null);
				break;
			case ResponseLongRentOrder.SUBSCRIBE_CODE:
				mLongTimeSubscribeFrament.setBean(mLongRentOrderBean.bean);
				showOrderFragment(mLongTimeSubscribeFrament);
				break;
			case ResponseLongRentOrder.OODER_CODE:
				mLongTimeRentCarFrament.setBean(mLongRentOrderBean.bean);
				showOrderFragment(mLongTimeRentCarFrament);
				break;
			default:
				break;
			}
			break;
		}
		case FLAG_PILE: {
			showOrderFragment(null);
		}
			break;
		case FLAG_BIGCUSTOME: {
			switch (mBigCustomerOrderBean.type) {
			case ResponseBigCustomerOrder.NO_ORDER_CODE:
				showOrderFragment(null);
				break;
			case ResponseBigCustomerOrder.OODER_CODE:
				showOrderFragment(null);
				break;
			case ResponseBigCustomerOrder.SUBSCRIBE_CODE:
				mDrawButton.setVisibility(View.VISIBLE);
				mBigCustomerSubscribeFrament.setData(mBigCustomerOrderBean.bean);
				showOrderFragment(mBigCustomerSubscribeFrament);
				break;
			default:
				break;
			}
			break;
		}
		default:
			break;
		}
		setSaoMaViSible();
	}

	/**
	 * 显示的fragment 如果为null表示要把所有的订单fragment隐藏
	 *
	 * @param fragment
	 */
	private void showOrderFragment(Fragment fragment) {

		FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
		boolean isCommit = false;
		if (this.fragment != null) {
			if (this.fragment != fragment || fragment == null) {
				transaction.hide(this.fragment);
				isCommit = true;
			}
		}
		if (fragment != null && this.fragment != fragment) {
			transaction.show(fragment);
			isCommit = true;
		}
		if (isCommit)
			transaction.commitAllowingStateLoss();
		this.fragment = fragment;
	}


	/**
	 * 获取充电桩地点
	 */
	public void get_all_network() {
		final Get_all_networkRequest requestBean = new Get_all_networkRequest();
		requestBean.times = Helper_SharedPreferences.get_int_sp(CodeConstant.Get_all_network_time);
		promptDialog.show();
		MyAppcation.getMyAppcation().getPostData(this, requestBean, new GetDataInterFace<String>() {

			@Override
			public void onResponse(String response) {
				promptDialog.dismiss();
				ResponseAllNetwork get_all_networkResponse = JSON.parseObject(response, ResponseAllNetwork.class);
				Helper_SharedPreferences.set_int_sp(CodeConstant.Get_all_network_time, get_all_networkResponse.times);
				if (get_all_networkResponse.is_update == 1) {

					String json = JSON.toJSONString(get_all_networkResponse.points);
					MyCache.getMyCache().putCache(requestBean.getUrl(), json);
					if (mPileList == null) {
						mPileList = new ArrayList<ClusterItem>();
					} else {
						mPileList.clear();
					}
					mPileList.addAll(get_all_networkResponse.points);
					setPoints(mPileList);
				} else {
					String json = MyCache.getMyCache().getCache(requestBean.getUrl());
					ArrayList<PileNetWork> listCache = (ArrayList<PileNetWork>) JSON
							.parseArray(json, PileNetWork.class);
					if (mPileList == null) {
						mPileList = new ArrayList<ClusterItem>();
					}
					mPileList.clear();
					mPileList.addAll(listCache);
					setPoints(mPileList);

				}

			}
		}, new DisssmissInterFace() {

			@Override
			public void putError(VolleyError error) {
				promptDialog.dismiss();
				String json = MyCache.getMyCache().getCache(requestBean.getUrl());
				if (json != null && !json.equals("")) {
					ArrayList<PileNetWork> listCache = (ArrayList<PileNetWork>) JSON
							.parseArray(json, PileNetWork.class);
					if (mPileList == null) {
						mPileList = new ArrayList<ClusterItem>();
					}
					mPileList.clear();
					for (ResponseAllNetwork.PileNetWork bean : listCache) {
						mPileList.add(bean);
					}
					setPoints(mPileList);
				}
			}
		});

	}

	/**
	 * 点击地图其他地方回调
	 */
	@Override
	public void onMapClick() {
		switch (flag_status) {
		case FLAG_SHORT_TIME:
			if (mShortTimeOrderBean.orderType == ResponseShortTimeOrder.OODER_CODE)
				orderShow();
			else
				mScrollDownLayout.setToExitOffset();
			break;
		case FLAG__LONG_RENT:
			break;
		case FLAG_PILE:
			if (start_chargeBean == null)
				mScrollDownLayout.setToExitOffset();
			else
				mScrollDownLayout.setToMinOffset();
			break;
		case FLAG_BIGCUSTOME:
			if (mBigCustomerOrderBean.type == ResponseBigCustomerOrder.OODER_CODE) {
				mScrollDownLayout.setToMinOffset();
			} else {
				mScrollDownLayout.setToExitOffset();
			}
			break;
		default:
			break;
		}
		mScrollDownLayoutLongRent.setToMaxOffset();
	}

	/**
	 * 点击网点marker infowindow导航，
	 */
	@Override
	public void onClickGo(final ClusterItem cluster) {

		LatLng latLng = cluster.getLatLng();
		if (MyAppcation.getMyAppcation().getMyLocation() != null) {
			Intent intent = new Intent(MyAppcation.getMyAppcation(), BasicNaviActivity.class);
			NaviLatLng mEndLatlng = new NaviLatLng(latLng.latitude, latLng.longitude);
			LatLng latlng = MyAppcation.getMyAppcation().getMyLocation();
			NaviLatLng mStartLatlng = new NaviLatLng(latlng.latitude, latlng.longitude);
			intent.putExtra("mStartLatlng", mStartLatlng);
			intent.putExtra("mEndLatlng", mEndLatlng);
			startActivity(intent);
		} else {
			Tools.showMessage("未获取到您的位置信息");
		}
	}

	/**
	 * 获取查看全景图回调
	 * @param cluster
	 */
	@Override
	public void onClickVisible(ClusterItem cluster) {
		GetNetworkImgsRequest reuqestBean = new GetNetworkImgsRequest();
		reuqestBean.networkId = cluster.getNetworkId();
		promptDialog.show();
		MyAppcation.getMyAppcation().getPostData(this, reuqestBean, new GetDataInterFace<String>() {

			@Override
			public void onResponse(String response) {
				promptDialog.dismiss();
				ArrayList<String> imgs = (ArrayList<String>) JSON.parseArray(response, String.class);
				if (imgs != null && imgs.size() > 0) {
					intent = new Intent(MyAppcation.getMyAppcation(), PanoramaActivity.class);
					intent.putExtra("imgs", imgs);
					startActivity(intent);
				} else {
					Tools.showMessage("当前网点无照片");
				}
			}
		}, mDisssmissInterFace);
	}

	/**
	 * 重写返回键事件
	 */
	public void onBackPressed() {
		if (!isExit) {
			isExit = true;
			onMapClick();
			new Handler().postDelayed(new Runnable() {

				@Override
				public void run() {
					isExit = false;
				}
			}, 2000);
		} else {
			// finish();
			MyAppcation.getMyAppcation().reMoveAllBaseInterFace();
		}
	}

	/**
	 * 设置顶部切换按钮,处理相应事件
	 *
	 * @param flag
	 */
	public void setFlag(int flag) {

		switch (flag) {
		case FLAG_SHORT_TIME:
			mMainBottomFragment.setFreshIsVisable(View.INVISIBLE);
			this.flag_status = FLAG_SHORT_TIME;
			setPoints(mShortList);
			setPage();
			break;
		case FLAG__LONG_RENT:
			mMainBottomFragment.setFreshIsVisable(View.INVISIBLE);
			mScrollDownLayout.setToExitOffset();
			this.flag_status = FLAG__LONG_RENT;
			setPoints(mLongList);
			if (MyAppcation.getMyAppcation().getUserBean() != null) {
				getLongRentOrderInfo();
			} else {
				setSaoMaViSible();
			}
			break;
		case FLAG_PILE:
			mMainBottomFragment.setFreshIsVisable(View.INVISIBLE);
			mScrollDownLayout.setToExitOffset();
			this.flag_status = FLAG_PILE;
			setOrderFragment();
			if (mPileList != null && mPileList.size() > 0) {
				setPoints(mPileList);
			} else {
				setPoints(null);
				get_all_network();
			}
			if (MyAppcation.getMyAppcation().getUserBean() != null) {
				getPileOrder();
			}
			break;
		case FLAG_BIGCUSTOME:
			this.flag_status = FLAG_BIGCUSTOME;
			mScrollDownLayout.setToExitOffset();
			mMainBottomFragment.setFreshIsVisable(View.VISIBLE);
			setPoints(null);
			getBigCustomerOrder();
			break;
		default:
			break;
		}

	}

	/**
	 * 设置扫码按钮的显示以及文字
	 */

	private void setSaoMaViSible() {
		if ((mShortTimeOrderBean.orderType == ResponseShortTimeOrder.NO_ORDER_CODE && flag_status == FLAG_SHORT_TIME)
				|| (mBigCustomerOrderBean.type == ResponseBigCustomerOrder.NO_ORDER_CODE && flag_status == FLAG_BIGCUSTOME)) {
			mMainBottomFragment.setScanVisable(View.VISIBLE);
			mMainBottomFragment.setScanText("扫码用车");
		} else if (flag_status == FLAG_PILE) {
			mMainBottomFragment.setScanVisable(View.VISIBLE);
			mMainBottomFragment.setScanText("扫码充电");
		} else {
			mMainBottomFragment.setScanVisable(View.INVISIBLE);
		}
	}

	/**
	 * 获取充电桩订单状态
	 */
	private void getPileOrder() {
		Check_orderRequest requestBean = new Check_orderRequest();
		GetDataInterFace<String> listener = new GetDataInterFace<String>() {

			@Override
			public void onResponse(String response) {

				promptDialog.dismiss();
				start_chargeBean = null;
				if (response.startsWith("["))
					return;
				final CheckOrderBean check_orderBean = JSON.parseObject(response, CheckOrderBean.class);
				if (check_orderBean.charging_order != null) {
					mScrollDownLayout.setToExitOffset();
					setPileOrder(check_orderBean.charging_order);
					start_chargeBean = check_orderBean.charging_order;
				} else if (check_orderBean.no_pay_order != null) {
					TipDialog tipDialog = new TipDialog(MainActivity.this, "温馨提示", "您有未支付的订单，去支付？",
							new MyDialogButton() {

								@Override
								public void setTitle(int flag, String str) {
									intent = new Intent(getApplicationContext(), PileOrderDetailActivity.class);
									intent.putExtra("orderId", check_orderBean.no_pay_order.orderNo);
									intent.putExtra("status", true);
									startActivity(intent);
								}
							});
					tipDialog.show();

				}

			}
		};
		promptDialog.show();
		MyAppcation.getMyAppcation().getPostData(this, requestBean, listener, mDisssmissInterFace);

	}

	@Override
	public void saveData(Bundle outState) {
		if (mMapView != null)
			mMapView.onSaveInstanceState(outState);
	}

	@Override
	public void getLastData(Bundle savedInstanceState) {

		if (savedInstanceState == null) {
			flag_status = FLAG_SHORT_TIME;
			isFirstInter = true;
			isInit = true;
		} else {
			finish();
			intent = new Intent(getApplicationContext(), MainActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
			startActivity(intent);
			isInit = false;
		}
	}

	@Override
	public void onScrollProgressChanged(float currentProgress) {

	}

	@Override
	public void onScrollProgressChanged(int offoxt) {
		Log.d("LDW",offoxt+"");
		if(fragmentList.get(0) instanceof ScrollInterFaceAble) {
			for (Fragment mFragment : fragmentList) {
				ScrollInterFaceAble mShortTimeCarInfoFragment = (ScrollInterFaceAble) mFragment;
				mShortTimeCarInfoFragment.setOffext(offoxt);
			}
		}
	}

	@Override
	public void onScrollFinished(Status currentStatus) {
		if (currentStatus == Status.EXIT) {
			orderShow();
		}
	}


}
